import { ConfigManager } from "../../../com/gengine/resource/ConfigManager";
import { TPetEquipStar } from "../../../Message/Db/Tables/TPetEquipStar";
import { TPetEquipUpdate } from "../../../Message/Db/Tables/TPetEquipUpdate";
import { ItemConfig } from "./ItemConfig";
import { PetEquipPrefixInfo } from "../view/petEquipment/info/PetEquipPrefixInfo";
import { TPetEquipPrefixAdd } from "../../../Message/Db/Tables/TPetEquipPrefixAdd";
type int = number;
//class PetEquipForgeConfig
    
    export  class PetEquipForgeConfig
    {
        constructor()
        {
            
            this._petEquipStarValueMap = new Map<any, any> /* flash.utils.Dictionary */();
            this._petEquipUpdateMap = new Map<any, any> /* flash.utils.Dictionary */();
            this._petEquipPrefixUpgradeConfig = new Map<any, any> /* flash.utils.Dictionary */();
            this._petEquipPrefixAddMap = new Map<any, any> /* flash.utils.Dictionary */();
            if (PetEquipForgeConfig._instance) 
            {
                throw new Error("PetEquipForgeConfig 单例");
            }
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            var loc1=null;
            loc1 = ConfigManager.instance.getJSONByFileName("t_pet_equip_star.json");
            this.writeEquipStar(loc1);
            loc1 = ConfigManager.instance.getJSONByFileName("t_pet_equip_update.json");
            this.writeCostConfig(loc1);
            this.initPrefixUpgradeConfig();
            loc1 = ConfigManager.instance.getJSONByFileName("t_pet_equip_prefix_add.json");
            this.writePrefixAddConfig(loc1);
            return;
        }

        /* internal  */writeEquipStar(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new TPetEquipStar();
                loc1.id = loc2.id;
                loc1.color = loc2.color;
                loc1.type = loc2.type;
                loc1.level = loc2.level;
                loc1.addrUpgrade = loc2.addrUpgrade;
                this._petEquipStarValueMap[loc1.id] = loc1;
            }
            return;
        }

        /* internal  */writeCostConfig(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new TPetEquipUpdate();
                loc1.color = loc2.color;
                loc1.cost = loc2.cost;
                loc1.id = loc2.id;
                loc1.oper = loc2.oper;
                this._petEquipUpdateMap[loc1.oper + "_" + loc1.color] = loc1;
            }
            return;
        }

        /* internal  */initPrefixUpgradeConfig(): void
        {
            var loc2=null;
            var loc3=null;
            var loc1=ItemConfig.instance.getItemUpdateArrayByOperation(ItemConfig.PetEquipPrefix);
            var loc4=0;
            var loc5=loc1;
            for(loc2 of loc5) 
            {
                loc3 = new PetEquipPrefixInfo(loc2.condition);
                this._petEquipPrefixUpgradeConfig[loc3.target] = loc3;
            }
            return;
        }

        /* internal  */writePrefixAddConfig(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new TPetEquipPrefixAdd();
                loc1.color = loc2.color;
                loc1.prefix = loc2.prefix;
                loc1.percent = loc2.percent;
                this._petEquipPrefixAddMap[loc1.color + "_" + loc1.prefix] = loc1;
            }
            return;
        }

        public getCost(arg1: int, arg2: int): int
        {
            var loc1=this._petEquipUpdateMap[arg1 + "_" + arg2];
            return loc1 ? loc1.cost : 0;
        }

        public getEquipBaseStarValue(arg1: int, arg2: int, arg3: int, arg4: int): number
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc4=0;
            var loc5=0;
            var loc6=this._petEquipStarValueMap;
            for(loc1 of loc6) 
            {
                if (!(loc1.type == arg1 && loc1.color == arg2 && loc1.level == arg3)) 
                {
                    continue;
                }
                loc2 = loc1.addrUpgrade.split("#");
                loc3 = loc1.addrUpgrade.split("#");
                loc4 = 0;
                while (loc4 < loc2.length) 
                {
                    if ((loc3 = (loc2[loc4] as string).split(",")).length == 2 && parseInt(loc3[0]) == arg4) 
                    {
                        return parseInt(loc3[1]) / 100;
                    }
                    ++loc4;
                }
            }
            return 0;
        }

        public getPrefixUpgateInfo(arg1: int): PetEquipPrefixInfo
        {
            return this._petEquipPrefixUpgradeConfig[arg1];
        }

        public getPrefixAddPercent(arg1: int, arg2: int): number
        {
            var loc1=this._petEquipPrefixAddMap[arg1 + "_" + arg2];
            if (loc1) 
            {
                return 1 + loc1.percent / 100;
            }
            return 1;
        }

        public static get instance(): PetEquipForgeConfig
        {
            if (!PetEquipForgeConfig._instance) 
            {
                PetEquipForgeConfig._instance = new PetEquipForgeConfig();
            }
            return PetEquipForgeConfig._instance;
        }

        /* internal */ /* var */_petEquipStarValueMap: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_petEquipUpdateMap: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_petEquipPrefixUpgradeConfig: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_petEquipPrefixAddMap: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ static /* var */_instance: PetEquipForgeConfig;
    }
